{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>名称</th>\n",
       "      <th>类别</th>\n",
       "      <th>单价</th>\n",
       "      <th>数量</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-07-01</td>\n",
       "      <td>商品A</td>\n",
       "      <td>服装</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-07-02</td>\n",
       "      <td>商品B</td>\n",
       "      <td>食品</td>\n",
       "      <td>200</td>\n",
       "      <td>3</td>\n",
       "      <td>600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-07-03</td>\n",
       "      <td>商品C</td>\n",
       "      <td>服装</td>\n",
       "      <td>2000</td>\n",
       "      <td>5</td>\n",
       "      <td>10000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-07-04</td>\n",
       "      <td>商品A</td>\n",
       "      <td>食品</td>\n",
       "      <td>22</td>\n",
       "      <td>7</td>\n",
       "      <td>154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-07-05</td>\n",
       "      <td>商品B</td>\n",
       "      <td>服装</td>\n",
       "      <td>220</td>\n",
       "      <td>8</td>\n",
       "      <td>1760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2019-07-06</td>\n",
       "      <td>商品C</td>\n",
       "      <td>食品</td>\n",
       "      <td>2220</td>\n",
       "      <td>4</td>\n",
       "      <td>8880</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2019-07-07</td>\n",
       "      <td>商品A</td>\n",
       "      <td>服装</td>\n",
       "      <td>600</td>\n",
       "      <td>3</td>\n",
       "      <td>1800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2019-07-08</td>\n",
       "      <td>商品B</td>\n",
       "      <td>食品</td>\n",
       "      <td>1200</td>\n",
       "      <td>1</td>\n",
       "      <td>1200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2019-07-09</td>\n",
       "      <td>商品C</td>\n",
       "      <td>服装</td>\n",
       "      <td>230</td>\n",
       "      <td>2</td>\n",
       "      <td>460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-07-10</td>\n",
       "      <td>商品A</td>\n",
       "      <td>食品</td>\n",
       "      <td>26</td>\n",
       "      <td>6</td>\n",
       "      <td>156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期   名称  类别    单价  数量     金额\n",
       "0 2019-07-01  商品A  服装    20   1     20\n",
       "1 2019-07-02  商品B  食品   200   3    600\n",
       "2 2019-07-03  商品C  服装  2000   5  10000\n",
       "3 2019-07-04  商品A  食品    22   7    154\n",
       "4 2019-07-05  商品B  服装   220   8   1760\n",
       "5 2019-07-06  商品C  食品  2220   4   8880\n",
       "6 2019-07-07  商品A  服装   600   3   1800\n",
       "7 2019-07-08  商品B  食品  1200   1   1200\n",
       "8 2019-07-09  商品C  服装   230   2    460\n",
       "9 2019-07-10  商品A  食品    26   6    156"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ex = pd.read_excel('./pysourse/商品.xls')\n",
    "ex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.generic.DataFrameGroupBy object at 0x000001C3BE3C8E48>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每个类别花了多少钱\n",
    "grouped = ex.groupby('类别')\n",
    "grouped"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "服装\n",
      "          日期   名称  类别    单价  数量     金额\n",
      "0 2019-07-01  商品A  服装    20   1     20\n",
      "2 2019-07-03  商品C  服装  2000   5  10000\n",
      "4 2019-07-05  商品B  服装   220   8   1760\n",
      "6 2019-07-07  商品A  服装   600   3   1800\n",
      "8 2019-07-09  商品C  服装   230   2    460\n",
      "食品\n",
      "          日期   名称  类别    单价  数量    金额\n",
      "1 2019-07-02  商品B  食品   200   3   600\n",
      "3 2019-07-04  商品A  食品    22   7   154\n",
      "5 2019-07-06  商品C  食品  2220   4  8880\n",
      "7 2019-07-08  商品B  食品  1200   1  1200\n",
      "9 2019-07-10  商品A  食品    26   6   156\n"
     ]
    }
   ],
   "source": [
    "for name,data in grouped:\n",
    "    print(name)\n",
    "    print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>数量</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>类别</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>服装</th>\n",
       "      <td>19</td>\n",
       "      <td>14040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>食品</th>\n",
       "      <td>21</td>\n",
       "      <td>10990</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    数量     金额\n",
       "类别           \n",
       "服装  19  14040\n",
       "食品  21  10990"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grouped['数量','金额'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "类别\n",
       "服装    2000\n",
       "食品    2220\n",
       "Name: 单价, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grouped['单价'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#通过2列进行分组\n",
    "grouped = ex.groupby(['类别','名称'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "类别  名称 \n",
       "服装  商品A     600\n",
       "    商品B     220\n",
       "    商品C    2000\n",
       "食品  商品A      26\n",
       "    商品B    1200\n",
       "    商品C    2220\n",
       "Name: 单价, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求类别中定商品的最高价格\n",
    "grouped['单价'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>单价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>类别</th>\n",
       "      <th>名称</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">服装</th>\n",
       "      <th>商品A</th>\n",
       "      <td>310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>商品B</th>\n",
       "      <td>220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>商品C</th>\n",
       "      <td>1115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">食品</th>\n",
       "      <th>商品A</th>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>商品B</th>\n",
       "      <td>700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>商品C</th>\n",
       "      <td>2220</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          单价\n",
       "类别 名称       \n",
       "服装 商品A   310\n",
       "   商品B   220\n",
       "   商品C  1115\n",
       "食品 商品A    24\n",
       "   商品B   700\n",
       "   商品C  2220"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#变成dataframe , 加[]\n",
    "grouped[['单价']].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## python中的time\n",
    "## time datetime\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1567729180.2880538"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time \n",
    "time.time()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2019, tm_mon=9, tm_mday=5, tm_hour=16, tm_min=17, tm_sec=53, tm_wday=3, tm_yday=248, tm_isdst=0)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime(1567671473)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2019-09-05 16:17:53'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(1567671473))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2019, tm_mon=9, tm_mday=5, tm_hour=16, tm_min=17, tm_sec=0, tm_wday=3, tm_yday=248, tm_isdst=-1)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "local = time.strptime('2019-09-05 16:17','%Y-%m-%d %H:%M')\n",
    "local"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1567671420.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.mktime(local)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2019, 9, 6, 8, 19, 36, 843698)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "now = datetime.now()\n",
    "now"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "now.year\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2019-09-05 16:46:23'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#ftime\n",
    "now.strftime('%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2019, 9, 5, 16, 17)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#ptime\n",
    "local = datetime.strptime('2019-09-05 16:17','%Y-%m-%d %H:%M')\n",
    "local"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2019, 9, 5, 16, 17)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "datetime.fromtimestamp(1567671420.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1567673183.826577"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#时间戳\n",
    "now.timestamp()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.timedelta(472, 60851, 292793)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#时间差\n",
    "delta = datetime.now() - datetime(2018,5,21)\n",
    "delta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-05-01', '2018-05-02', '2018-05-03', '2018-05-04',\n",
       "               '2018-05-05', '2018-05-06', '2018-05-07', '2018-05-08',\n",
       "               '2018-05-09', '2018-05-10',\n",
       "               ...\n",
       "               '2018-09-22', '2018-09-23', '2018-09-24', '2018-09-25',\n",
       "               '2018-09-26', '2018-09-27', '2018-09-28', '2018-09-29',\n",
       "               '2018-09-30', '2018-10-01'],\n",
       "              dtype='datetime64[ns]', length=154, freq='D')"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#pandas时间序列\n",
    "#初始化时间序列 按天计算\n",
    "pd.date_range('2018-5-1','2018-10-1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-05-06', '2018-05-13', '2018-05-20', '2018-05-27',\n",
       "               '2018-06-03', '2018-06-10', '2018-06-17', '2018-06-24',\n",
       "               '2018-07-01', '2018-07-08', '2018-07-15', '2018-07-22',\n",
       "               '2018-07-29', '2018-08-05', '2018-08-12', '2018-08-19',\n",
       "               '2018-08-26', '2018-09-02', '2018-09-09', '2018-09-16',\n",
       "               '2018-09-23', '2018-09-30'],\n",
       "              dtype='datetime64[ns]', freq='W-SUN')"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#初始化时间序列 按周计算\n",
    "pd.date_range('2018-5-1','2018-10-1',freq = 'w')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-06-30', '2018-09-30', '2018-12-31', '2019-03-31',\n",
       "               '2019-06-30', '2019-09-30', '2019-12-31', '2020-03-31',\n",
       "               '2020-06-30', '2020-09-30'],\n",
       "              dtype='datetime64[ns]', freq='Q-DEC')"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#D 天 ，w 周， M 月 ，Q季度，H小时，T分 S秒\n",
    "pd.date_range('2018-05-01',freq = 'Q',periods = 10)  #从5月开始返回10个季度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-08-19 00:00:00</td>\n",
       "      <td>11.338226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-08-19 00:01:00</td>\n",
       "      <td>9.637950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-08-19 00:02:00</td>\n",
       "      <td>9.441065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-08-19 00:03:00</td>\n",
       "      <td>11.575345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-08-19 00:04:00</td>\n",
       "      <td>9.101720</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 time        cpu\n",
       "0 2019-08-19 00:00:00  11.338226\n",
       "1 2019-08-19 00:01:00   9.637950\n",
       "2 2019-08-19 00:02:00   9.441065\n",
       "3 2019-08-19 00:03:00  11.575345\n",
       "4 2019-08-19 00:04:00   9.101720"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#模拟log监控服务器CPU功率\n",
    "#生成log日志\n",
    "data = {\n",
    "    'time':pd.date_range('2019-08-19',periods  = 200000,freq = 'T'),\n",
    "    'cpu':np.random.randn(200000)+10\n",
    "}\n",
    "df=pd.DataFrame(data,columns = ['time','cpu'])\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 200000 entries, 0 to 199999\n",
      "Data columns (total 2 columns):\n",
      "time    200000 non-null datetime64[ns]\n",
      "cpu     200000 non-null float64\n",
      "dtypes: datetime64[ns](1), float64(1)\n",
      "memory usage: 3.1 MB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3360</th>\n",
       "      <td>2019-08-21 08:00:00</td>\n",
       "      <td>8.785911</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3361</th>\n",
       "      <td>2019-08-21 08:01:00</td>\n",
       "      <td>10.571627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3362</th>\n",
       "      <td>2019-08-21 08:02:00</td>\n",
       "      <td>10.153059</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3363</th>\n",
       "      <td>2019-08-21 08:03:00</td>\n",
       "      <td>11.020188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3364</th>\n",
       "      <td>2019-08-21 08:04:00</td>\n",
       "      <td>9.127473</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3365</th>\n",
       "      <td>2019-08-21 08:05:00</td>\n",
       "      <td>9.405613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3366</th>\n",
       "      <td>2019-08-21 08:06:00</td>\n",
       "      <td>10.744136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3367</th>\n",
       "      <td>2019-08-21 08:07:00</td>\n",
       "      <td>11.094122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3368</th>\n",
       "      <td>2019-08-21 08:08:00</td>\n",
       "      <td>10.541824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3369</th>\n",
       "      <td>2019-08-21 08:09:00</td>\n",
       "      <td>10.487908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3370</th>\n",
       "      <td>2019-08-21 08:10:00</td>\n",
       "      <td>12.155244</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    time        cpu\n",
       "3360 2019-08-21 08:00:00   8.785911\n",
       "3361 2019-08-21 08:01:00  10.571627\n",
       "3362 2019-08-21 08:02:00  10.153059\n",
       "3363 2019-08-21 08:03:00  11.020188\n",
       "3364 2019-08-21 08:04:00   9.127473\n",
       "3365 2019-08-21 08:05:00   9.405613\n",
       "3366 2019-08-21 08:06:00  10.744136\n",
       "3367 2019-08-21 08:07:00  11.094122\n",
       "3368 2019-08-21 08:08:00  10.541824\n",
       "3369 2019-08-21 08:09:00  10.487908\n",
       "3370 2019-08-21 08:10:00  12.155244"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查询10分钟内的cpu占用率\n",
    "df[(df.time >= '2019-08-21 08:00:00')&(df.time <= '2019-08-21 08:10:00')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:00:00</th>\n",
       "      <td>2019-08-19 00:00:00</td>\n",
       "      <td>11.338226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:01:00</th>\n",
       "      <td>2019-08-19 00:01:00</td>\n",
       "      <td>9.637950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:02:00</th>\n",
       "      <td>2019-08-19 00:02:00</td>\n",
       "      <td>9.441065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:03:00</th>\n",
       "      <td>2019-08-19 00:03:00</td>\n",
       "      <td>11.575345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:04:00</th>\n",
       "      <td>2019-08-19 00:04:00</td>\n",
       "      <td>9.101720</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   time        cpu\n",
       "time                                              \n",
       "2019-08-19 00:00:00 2019-08-19 00:00:00  11.338226\n",
       "2019-08-19 00:01:00 2019-08-19 00:01:00   9.637950\n",
       "2019-08-19 00:02:00 2019-08-19 00:02:00   9.441065\n",
       "2019-08-19 00:03:00 2019-08-19 00:03:00  11.575345\n",
       "2019-08-19 00:04:00 2019-08-19 00:04:00   9.101720"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#为了查看1个小时内cpu占用情况，现在是一分钟采样，数据太多，改造dataframe\n",
    "#让时间为索引，改造成5分钟一次时间为所有，求5分钟的平均值\n",
    "s = pd.to_datetime(df.time)\n",
    "df.index = s\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:00:00</th>\n",
       "      <td>11.338226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:01:00</th>\n",
       "      <td>9.637950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:02:00</th>\n",
       "      <td>9.441065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:03:00</th>\n",
       "      <td>11.575345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:04:00</th>\n",
       "      <td>9.101720</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           cpu\n",
       "time                          \n",
       "2019-08-19 00:00:00  11.338226\n",
       "2019-08-19 00:01:00   9.637950\n",
       "2019-08-19 00:02:00   9.441065\n",
       "2019-08-19 00:03:00  11.575345\n",
       "2019-08-19 00:04:00   9.101720"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除time列，让索引成为时间\n",
    "df = df.drop('time',axis=1)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "DatetimeIndex: 200000 entries, 2019-08-19 00:00:00 to 2020-01-04 21:19:00\n",
      "Data columns (total 1 columns):\n",
      "cpu    200000 non-null float64\n",
      "dtypes: float64(1)\n",
      "memory usage: 3.1 MB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:00:00</th>\n",
       "      <td>9.607438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:01:00</th>\n",
       "      <td>12.076238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:02:00</th>\n",
       "      <td>10.433011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:03:00</th>\n",
       "      <td>10.201790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:04:00</th>\n",
       "      <td>10.317819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:05:00</th>\n",
       "      <td>9.486336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:06:00</th>\n",
       "      <td>10.265270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:07:00</th>\n",
       "      <td>9.436270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:08:00</th>\n",
       "      <td>11.397947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:09:00</th>\n",
       "      <td>12.077459</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 08:10:00</th>\n",
       "      <td>9.228123</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           cpu\n",
       "time                          \n",
       "2019-08-21 08:00:00   9.607438\n",
       "2019-08-21 08:01:00  12.076238\n",
       "2019-08-21 08:02:00  10.433011\n",
       "2019-08-21 08:03:00  10.201790\n",
       "2019-08-21 08:04:00  10.317819\n",
       "2019-08-21 08:05:00   9.486336\n",
       "2019-08-21 08:06:00  10.265270\n",
       "2019-08-21 08:07:00   9.436270\n",
       "2019-08-21 08:08:00  11.397947\n",
       "2019-08-21 08:09:00  12.077459\n",
       "2019-08-21 08:10:00   9.228123"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#由时间为索引，简单查询10分钟内的cpu占用率\n",
    "df['2019-08-21 08:00:00':'2019-08-21 08:10:00']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:00:00</th>\n",
       "      <td>9.066042</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:01:00</th>\n",
       "      <td>9.900593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:02:00</th>\n",
       "      <td>9.413357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:03:00</th>\n",
       "      <td>10.225940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:04:00</th>\n",
       "      <td>9.601721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:05:00</th>\n",
       "      <td>8.983101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:06:00</th>\n",
       "      <td>9.089040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:07:00</th>\n",
       "      <td>8.486237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:08:00</th>\n",
       "      <td>9.452612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:09:00</th>\n",
       "      <td>11.025221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:10:00</th>\n",
       "      <td>8.797789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:11:00</th>\n",
       "      <td>8.932896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:12:00</th>\n",
       "      <td>11.284830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:13:00</th>\n",
       "      <td>10.635872</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:14:00</th>\n",
       "      <td>9.957623</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:15:00</th>\n",
       "      <td>9.898325</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:16:00</th>\n",
       "      <td>7.579662</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:17:00</th>\n",
       "      <td>10.288827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:18:00</th>\n",
       "      <td>10.372956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:19:00</th>\n",
       "      <td>9.870047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:20:00</th>\n",
       "      <td>11.225915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:21:00</th>\n",
       "      <td>10.843280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:22:00</th>\n",
       "      <td>9.261511</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:23:00</th>\n",
       "      <td>8.951906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:24:00</th>\n",
       "      <td>11.507074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:25:00</th>\n",
       "      <td>9.771382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:26:00</th>\n",
       "      <td>9.656410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:27:00</th>\n",
       "      <td>10.734572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:28:00</th>\n",
       "      <td>11.778185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 00:29:00</th>\n",
       "      <td>8.790065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:30:00</th>\n",
       "      <td>9.318788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:31:00</th>\n",
       "      <td>9.845837</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:32:00</th>\n",
       "      <td>8.719468</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:33:00</th>\n",
       "      <td>10.615461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:34:00</th>\n",
       "      <td>9.704491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:35:00</th>\n",
       "      <td>9.477084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:36:00</th>\n",
       "      <td>9.533853</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:37:00</th>\n",
       "      <td>11.276395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:38:00</th>\n",
       "      <td>10.224112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:39:00</th>\n",
       "      <td>9.706462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:40:00</th>\n",
       "      <td>10.926254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:41:00</th>\n",
       "      <td>10.046764</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:42:00</th>\n",
       "      <td>10.452043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:43:00</th>\n",
       "      <td>9.977402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:44:00</th>\n",
       "      <td>11.587175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:45:00</th>\n",
       "      <td>9.119590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:46:00</th>\n",
       "      <td>11.083739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:47:00</th>\n",
       "      <td>11.500033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:48:00</th>\n",
       "      <td>10.050773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:49:00</th>\n",
       "      <td>9.376112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:50:00</th>\n",
       "      <td>9.981368</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:51:00</th>\n",
       "      <td>11.024202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:52:00</th>\n",
       "      <td>9.302200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:53:00</th>\n",
       "      <td>10.609239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:54:00</th>\n",
       "      <td>10.813134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:55:00</th>\n",
       "      <td>9.959476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:56:00</th>\n",
       "      <td>10.952233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:57:00</th>\n",
       "      <td>9.446531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:58:00</th>\n",
       "      <td>8.826631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21 23:59:00</th>\n",
       "      <td>10.638252</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1440 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                           cpu\n",
       "time                          \n",
       "2019-08-21 00:00:00   9.066042\n",
       "2019-08-21 00:01:00   9.900593\n",
       "2019-08-21 00:02:00   9.413357\n",
       "2019-08-21 00:03:00  10.225940\n",
       "2019-08-21 00:04:00   9.601721\n",
       "...                        ...\n",
       "2019-08-21 23:55:00   9.959476\n",
       "2019-08-21 23:56:00  10.952233\n",
       "2019-08-21 23:57:00   9.446531\n",
       "2019-08-21 23:58:00   8.826631\n",
       "2019-08-21 23:59:00  10.638252\n",
       "\n",
       "[1440 rows x 1 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求出一天的数据，直接输入日期\n",
    "df['2019-08-21']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-19</th>\n",
       "      <td>9.997677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-20</th>\n",
       "      <td>10.033103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-21</th>\n",
       "      <td>9.998437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-22</th>\n",
       "      <td>9.972839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-23</th>\n",
       "      <td>10.006402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-24</th>\n",
       "      <td>9.946408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-25</th>\n",
       "      <td>9.986400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-26</th>\n",
       "      <td>10.030713</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-27</th>\n",
       "      <td>9.994264</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-28</th>\n",
       "      <td>10.017036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-29</th>\n",
       "      <td>9.990285</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-30</th>\n",
       "      <td>10.006308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-31</th>\n",
       "      <td>9.979758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-01</th>\n",
       "      <td>10.002762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-02</th>\n",
       "      <td>10.009936</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-03</th>\n",
       "      <td>10.058418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-04</th>\n",
       "      <td>9.954094</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-05</th>\n",
       "      <td>10.021860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-06</th>\n",
       "      <td>10.013946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-07</th>\n",
       "      <td>9.963252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-08</th>\n",
       "      <td>10.005165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-09</th>\n",
       "      <td>9.994691</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-10</th>\n",
       "      <td>9.961239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-11</th>\n",
       "      <td>10.047344</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-12</th>\n",
       "      <td>10.020402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-13</th>\n",
       "      <td>10.017038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-14</th>\n",
       "      <td>9.991890</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-15</th>\n",
       "      <td>9.976549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-16</th>\n",
       "      <td>10.038130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-09-17</th>\n",
       "      <td>9.980279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-06</th>\n",
       "      <td>10.004935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-07</th>\n",
       "      <td>9.972262</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-08</th>\n",
       "      <td>9.996761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-09</th>\n",
       "      <td>9.979948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-10</th>\n",
       "      <td>9.984063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-11</th>\n",
       "      <td>9.990527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-12</th>\n",
       "      <td>10.007255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-13</th>\n",
       "      <td>10.036819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-14</th>\n",
       "      <td>10.029850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-15</th>\n",
       "      <td>10.017154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-16</th>\n",
       "      <td>10.011955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-17</th>\n",
       "      <td>9.959474</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-18</th>\n",
       "      <td>10.005626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-19</th>\n",
       "      <td>9.989039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-20</th>\n",
       "      <td>9.994528</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-21</th>\n",
       "      <td>10.064922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-22</th>\n",
       "      <td>10.027743</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-23</th>\n",
       "      <td>10.038973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-24</th>\n",
       "      <td>10.009179</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-25</th>\n",
       "      <td>10.029696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-26</th>\n",
       "      <td>10.021518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-27</th>\n",
       "      <td>10.011995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-28</th>\n",
       "      <td>9.964895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-29</th>\n",
       "      <td>10.037613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-30</th>\n",
       "      <td>9.985405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-31</th>\n",
       "      <td>9.998519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-01</th>\n",
       "      <td>10.018073</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-02</th>\n",
       "      <td>10.044822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-03</th>\n",
       "      <td>10.024505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04</th>\n",
       "      <td>10.056657</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>139 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  cpu\n",
       "2019-08-19   9.997677\n",
       "2019-08-20  10.033103\n",
       "2019-08-21   9.998437\n",
       "2019-08-22   9.972839\n",
       "2019-08-23  10.006402\n",
       "...               ...\n",
       "2019-12-31   9.998519\n",
       "2020-01-01  10.018073\n",
       "2020-01-02  10.044822\n",
       "2020-01-03  10.024505\n",
       "2020-01-04  10.056657\n",
       "\n",
       "[139 rows x 1 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按日期分组，求平均值\n",
    "df.groupby(df.index.date).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.008054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.985640</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9.990678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9.998389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9.974759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>10.012715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9.994698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>9.986819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>10.005459</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.994069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.014019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>10.015099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>10.012811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>10.014168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>10.032603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>9.991736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>10.005957</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>9.989756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>10.013876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>9.991863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>9.982715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>9.998886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>10.012228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>10.008668</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            cpu\n",
       "time           \n",
       "0     10.008054\n",
       "1      9.985640\n",
       "2      9.990678\n",
       "3      9.998389\n",
       "4      9.974759\n",
       "5     10.012715\n",
       "6      9.994698\n",
       "7      9.986819\n",
       "8     10.005459\n",
       "9      9.994069\n",
       "10    10.014019\n",
       "11    10.015099\n",
       "12    10.012811\n",
       "13    10.014168\n",
       "14    10.032603\n",
       "15     9.991736\n",
       "16    10.005957\n",
       "17     9.989756\n",
       "18    10.013876\n",
       "19     9.991863\n",
       "20     9.982715\n",
       "21     9.998886\n",
       "22    10.012228\n",
       "23    10.008668"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按小时分组统计，求平均值\n",
    "df.groupby(df.index.hour).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.020664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>9.991609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>10.003018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>10.003810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>10.001308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>10.007374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>10.002488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>10.004302</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>9.980454</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>10.008835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>10.001645</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>10.005354</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>9.991281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>9.989347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>10.001614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>9.994066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>9.995105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>10.006517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>10.007612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>10.016267</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            cpu\n",
       "time           \n",
       "1     10.020664\n",
       "34     9.991609\n",
       "35    10.003018\n",
       "36    10.003810\n",
       "37    10.001308\n",
       "38    10.007374\n",
       "39    10.002488\n",
       "40    10.004302\n",
       "41     9.980454\n",
       "42    10.008835\n",
       "43    10.001645\n",
       "44    10.005354\n",
       "45     9.991281\n",
       "46     9.989347\n",
       "47    10.001614\n",
       "48     9.994066\n",
       "49     9.995105\n",
       "50    10.006517\n",
       "51    10.007612\n",
       "52    10.016267"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按周分组统计，求平均值\n",
    "df.groupby(df.index.week).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cpu</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:00:00</th>\n",
       "      <td>10.218861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:05:00</th>\n",
       "      <td>9.565377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:10:00</th>\n",
       "      <td>9.335413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:15:00</th>\n",
       "      <td>10.797804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:20:00</th>\n",
       "      <td>10.353252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:25:00</th>\n",
       "      <td>9.846738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:30:00</th>\n",
       "      <td>10.438183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:35:00</th>\n",
       "      <td>10.052371</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:40:00</th>\n",
       "      <td>9.615119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:45:00</th>\n",
       "      <td>10.525664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:50:00</th>\n",
       "      <td>9.848532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 00:55:00</th>\n",
       "      <td>10.698582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:00:00</th>\n",
       "      <td>10.218734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:05:00</th>\n",
       "      <td>9.310635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:10:00</th>\n",
       "      <td>9.887477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:15:00</th>\n",
       "      <td>10.301521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:20:00</th>\n",
       "      <td>10.215905</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:25:00</th>\n",
       "      <td>9.987084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:30:00</th>\n",
       "      <td>9.393101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:35:00</th>\n",
       "      <td>9.710862</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:40:00</th>\n",
       "      <td>10.040505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:45:00</th>\n",
       "      <td>10.091939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:50:00</th>\n",
       "      <td>10.077386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 01:55:00</th>\n",
       "      <td>9.380851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 02:00:00</th>\n",
       "      <td>9.596923</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 02:05:00</th>\n",
       "      <td>10.096138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 02:10:00</th>\n",
       "      <td>10.146643</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 02:15:00</th>\n",
       "      <td>9.775722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 02:20:00</th>\n",
       "      <td>8.854218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-19 02:25:00</th>\n",
       "      <td>9.269168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 18:50:00</th>\n",
       "      <td>10.279153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 18:55:00</th>\n",
       "      <td>10.952901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:00:00</th>\n",
       "      <td>9.289855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:05:00</th>\n",
       "      <td>9.551409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:10:00</th>\n",
       "      <td>10.211554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:15:00</th>\n",
       "      <td>9.633126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:20:00</th>\n",
       "      <td>9.245339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:25:00</th>\n",
       "      <td>10.674758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:30:00</th>\n",
       "      <td>9.534719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:35:00</th>\n",
       "      <td>10.609882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:40:00</th>\n",
       "      <td>9.544627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:45:00</th>\n",
       "      <td>9.977049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:50:00</th>\n",
       "      <td>10.056111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 19:55:00</th>\n",
       "      <td>9.602092</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:00:00</th>\n",
       "      <td>10.367169</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:05:00</th>\n",
       "      <td>10.606213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:10:00</th>\n",
       "      <td>9.203790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:15:00</th>\n",
       "      <td>9.838122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:20:00</th>\n",
       "      <td>9.962194</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:25:00</th>\n",
       "      <td>10.446887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:30:00</th>\n",
       "      <td>10.599518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:35:00</th>\n",
       "      <td>9.916551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:40:00</th>\n",
       "      <td>10.219340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:45:00</th>\n",
       "      <td>9.751063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:50:00</th>\n",
       "      <td>9.859754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 20:55:00</th>\n",
       "      <td>10.279472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 21:00:00</th>\n",
       "      <td>9.912596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 21:05:00</th>\n",
       "      <td>10.400913</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 21:10:00</th>\n",
       "      <td>9.428991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04 21:15:00</th>\n",
       "      <td>9.822279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>40000 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                           cpu\n",
       "time                          \n",
       "2019-08-19 00:00:00  10.218861\n",
       "2019-08-19 00:05:00   9.565377\n",
       "2019-08-19 00:10:00   9.335413\n",
       "2019-08-19 00:15:00  10.797804\n",
       "2019-08-19 00:20:00  10.353252\n",
       "...                        ...\n",
       "2020-01-04 20:55:00  10.279472\n",
       "2020-01-04 21:00:00   9.912596\n",
       "2020-01-04 21:05:00  10.400913\n",
       "2020-01-04 21:10:00   9.428991\n",
       "2020-01-04 21:15:00   9.822279\n",
       "\n",
       "[40000 rows x 1 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按每5分钟分组统计，求平均值   5分钟采样\n",
    "df.resample('5T').mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
